'use strict';
module.exports = {
	/**
	 * 查询资源
	 * @url client/resource/pub/getList 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} classify_id  分类ID
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------
		let { classify_id, page, pageSize } = data;

		let whereJson = {
			status: 1
		};

		if(!vk.pubfn.isNull(classify_id) && classify_id !== 0) {
			whereJson["classify_id"] = classify_id;
		}

		let dbName = "db-resource";

		res["data"] = await vk.baseDao.selects({
			dbName,
			getMain: true,
			whereJson,
			pageIndex: page || 1,
			pageSize: pageSize || 10,
			fieldJson: {
				wx_openid: false,
				dbank_url: false,
				dbank_code: false
			},
			sort: [{name: "is_push", type: "desc"}, {name: "visit_num", type: "desc"}, {name: "buy_num", type: "desc"}, {name: "_add_time", type: "desc"}]
		})
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
